const Router = require('@koa/router');
const accommodationController = require('../controllers/accommodationController');

const router = new Router({ prefix: '/api/accommodation' });

// 获取所有可用的住宿信息
/**
 * @swagger
 * /api/accommodation/list:
 *   get:
 *     summary: 获取所有可用的住宿信息
 *     parameters:
 *       - in: query
 *         name: scenic_id
 *         schema:
 *           type: integer
 *         description: 景点 ID
 *       - in: query
 *         name: category
 *         schema:
 *           type: string
 *         description: 住宿类别（如“酒店”、“民宿”）
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *         description: 页码（默认 1）
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *         description: 每页条数（默认 10）
 *     responses:
 *       200:
 *         description: 成功获取住宿信息
 *       500:
 *         description: 获取失败
 */
router.get('/list', accommodationController.getAccommodationList);

// 获取单个住宿信息的详细内容
/**
 * @swagger
 * /api/accommodation/{id}:
 *   get:
 *     summary: 获取单个住宿信息的详细内容
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 住宿 ID
 *     responses:
 *       200:
 *         description: 成功获取住宿详情
 *       500:
 *         description: 获取失败
 */
router.get('/:id', accommodationController.getAccommodationById);

// 创建一个新的住宿信息
/**
 * @swagger
 * /api/accommodation/create:
 *   post:
 *     summary: 创建一个新的住宿信息
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               scenic_id:
 *                 type: integer
 *               accommodation_type:
 *                 type: string
 *               name:
 *                 type: string
 *               price_per_night:
 *                 type: number
 *               description:
 *                 type: string
 *               address:
 *                 type: string
 *               contact:
 *                 type: string
 *               available_rooms:
 *                 type: integer
 *     responses:
 *       201:
 *         description: 住宿信息创建成功
 *       500:
 *         description: 创建失败
 */
router.post('/create', accommodationController.createAccommodation);

// 用户预定住宿
/**
 * @swagger
 * /api/accommodation/book:
 *   post:
 *     summary: 用户预定住宿
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               user_id:
 *                 type: integer
 *               accommodation_id:
 *                 type: integer
 *               check_in_date:
 *                 type: string
 *               check_out_date:
 *                 type: string
 *     responses:
 *       201:
 *         description: 预订成功
 *       500:
 *         description: 预订失败
 */
router.post('/book', accommodationController.bookAccommodation);

// 获取用户预定的住宿记录
/**
 * @swagger
 * /api/accommodation/reservations/{user_id}:
 *   get:
 *     summary: 获取用户预定的住宿记录
 *     parameters:
 *       - in: path
 *         name: user_id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 用户 ID
 *     responses:
 *       200:
 *         description: 成功获取预订记录
 *       500:
 *         description: 获取失败
 */
router.get('/reservations/:user_id', accommodationController.getUserReservations);

// 取消预订
/**
 * @swagger
 * /api/accommodation/cancel:
 *   post:
 *     summary: 取消预订
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               user_id:
 *                 type: integer
 *               reservation_id:
 *                 type: integer
 *     responses:
 *       200:
 *         description: 预订取消成功
 *       500:
 *         description: 取消预订失败
 */
router.post('/cancel', accommodationController.cancelReservation);

module.exports = router;